//std::shared_ptr是一种智能指针，能记录有多少个指针指向了同一个对象，计数变为0的时候对象自动毁灭 这样可以取代delete
//std::make_shared会分配指定的对象并返回std::share_ptr指针 只有取代new
#include <memory>
#include "include.h"
void test_make_share_ptr()
{
	auto pointer = std::make_shared<int>(10);
	auto pointer2 = pointer;    // 引用计数+1
	auto pointer3 = pointer;    // 引用计数+1
	int *p = pointer.get();     // 这样不会增加引用计数

	cout << "pointer.use_count() = " << pointer.use_count() << endl;      // 3
	cout << "pointer2.use_count() = " << pointer2.use_count() << endl;    // 3
	cout << "pointer3.use_count() = " << pointer3.use_count() << endl;    // 3

	pointer2.reset();
	cout << "reset pointer2:" << endl;
	cout << "pointer.use_count() = " << pointer.use_count() << endl;      // 2
	cout << "pointer2.use_count() = " << pointer2.use_count() << endl;    // 0, pointer2 已 reset
	cout << "pointer3.use_count() = " << pointer3.use_count() << endl;    // 2

	pointer3.reset();
	cout << "reset pointer3:" << endl;
	cout << "pointer.use_count() = " << pointer.use_count() << endl;      // 1
	cout << "pointer2.use_count() = " << pointer2.use_count() << endl;    // 0
	cout << "pointer3.use_count() = " << pointer3.use_count() << endl;    // 0, pointer3 已 reset
}